home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / QuickTime VR / MacOS / QuickDraw™ 3D 1.0.6F4 SDK / Samples / SampleCode / Tumbler and Podium / Tumbler_HideMenuBar.c < prev    next >
Encoding:
Text File  |  1995-06-05  |  2.8 KB  |  123 lines  |  [TEXT/MPCC]

  1. // hack.  If god had meant programmers to mess with the menu bar, he'd have 
  2. // provided a menu manager routine to accomplish this.
  3. //
  4. // Why is this code so skanky?
  5. // • it relies on static variable
  6. // • it relies on the complier auto initializing new variables to nil
  7. //   to ensure that the regions get corrected properly
  8. // • it relies on manipulating low memory globals to which there may be no
  9. //   access in future
  10. // • it doesn't really work too well (try a context switch, the grayrgn
  11. //   needs fixing up when you switch back)
  12. //
  13.  
  14. #include <LowMem.h>
  15. #include <Windows.h>
  16. #include "tumbler_hidemenubar.h"
  17.  
  18.  
  19. static Boolean         pMbarIsVisible = true ;
  20. static short         pOldMBarHeight = 0 ;         // saves the menu bar height
  21. static RgnHandle    pOldGrayRgn = nil;
  22. static RgnHandle    pMenuRgn = nil ;
  23. static Rect            pMenuRect ;
  24. static RgnHandle    pCopyGrayRgn ;
  25.  
  26.  
  27.  
  28. void ToggleMenuBar(void)
  29. {
  30.     WindowRef            frontWindow ;
  31.     
  32.     if((frontWindow = (WindowRef)FrontWindow()) == nil)
  33.         return ;
  34.     
  35.     if( pOldGrayRgn == nil ) {
  36.         pOldGrayRgn = NewRgn() ;
  37.     }
  38.     
  39.     if( pMenuRgn == nil ) {
  40.         pMenuRgn = NewRgn() ;
  41.     }    
  42.     
  43.     if( pOldMBarHeight == 0 ) {
  44.         pOldMBarHeight = LMGetMBarHeight() ;
  45.     }
  46.     
  47.     if( pMbarIsVisible ) {
  48.         // hide the menubar
  49.         
  50.         // store the grayrgn
  51.         CopyRgn(GetGrayRgn(), pOldGrayRgn);
  52.  
  53.         // reset the menu bar height
  54.         LMSetMBarHeight(0) ;
  55.  
  56.         // save the menu rect
  57.         pMenuRect = qd.screenBits.bounds;
  58.         pMenuRect.bottom = pOldMBarHeight;
  59.         RectRgn(pMenuRgn, &pMenuRect);
  60.  
  61.         // and add this to the global grayrgn
  62.         pCopyGrayRgn = GetGrayRgn() ;
  63.         UnionRgn(pCopyGrayRgn, pMenuRgn, pCopyGrayRgn);
  64.         LMSetGrayRgn( pCopyGrayRgn ) ;
  65.         
  66.         PaintBehind( frontWindow, pMenuRgn);
  67.         CalcVisBehind( frontWindow, pMenuRgn);
  68.     }
  69.     else {
  70.         // Show the menubar
  71.         
  72.         // reset the menu bar height
  73.         LMSetMBarHeight( pOldMBarHeight );
  74.         
  75.         // update the grayrgn
  76.         XorRgn(pCopyGrayRgn,pMenuRgn,pCopyGrayRgn) ;
  77.         LMSetGrayRgn( pCopyGrayRgn ) ;
  78.         
  79.         // calc the rect occupied by the menu bar
  80.         pMenuRect = qd.screenBits.bounds;
  81.         pMenuRect.bottom = pOldMBarHeight;
  82.         RectRgn(pOldGrayRgn, &pMenuRect);
  83.  
  84.         PaintBehind( frontWindow, pCopyGrayRgn);
  85.         CalcVisBehind( frontWindow, pCopyGrayRgn);
  86.  
  87.         // draw the menubar in
  88.         DrawMenuBar();
  89.     }
  90.     pMbarIsVisible = !pMbarIsVisible ;
  91.     
  92.     return ;
  93. }
  94.  
  95. void FixGrayRgnAfterContextSwitch( void ) 
  96. {
  97.     WindowRef            frontWindow ;
  98.     
  99.     if((frontWindow = (WindowRef)FrontWindow()) == nil)
  100.         return ;
  101.  
  102.     if(!pMbarIsVisible) {
  103.         // store the grayrgn
  104.         CopyRgn(GetGrayRgn(), pOldGrayRgn);
  105.  
  106.         // reset the menu bar height
  107.         LMSetMBarHeight(0) ;
  108.  
  109.         // save the menu rect
  110.         pMenuRect = qd.screenBits.bounds;
  111.         pMenuRect.bottom = pOldMBarHeight;
  112.         RectRgn(pMenuRgn, &pMenuRect);
  113.  
  114.         // and add this to the global grayrgn
  115.         pCopyGrayRgn = GetGrayRgn() ;
  116.         UnionRgn(pCopyGrayRgn, pMenuRgn, pCopyGrayRgn);
  117.         LMSetGrayRgn( pCopyGrayRgn ) ;
  118.         
  119.         PaintBehind( frontWindow, pMenuRgn);
  120.         CalcVisBehind( frontWindow, pMenuRgn);
  121.     
  122.     }
  123. }